package com.xja.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xja.mapper.ArticleMapper;
import com.xja.pojo.Article;
import com.xja.pojo.ArticleCollInfo;
import com.xja.pojo.ArticleComment;
import com.xja.pojo.ArticleCheckMessage;
import com.xja.service.ArticleService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @作者:褚
 * @工程名:xja_blog
 * @方法:ArticleServiceImpl
 * @创建时间:2022/4/17 22:51
 */
@Service
public class ArticleServiceImpl implements ArticleService {
    @Autowired
    private ArticleMapper articleMapper;
    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public void addArticle(Article article) {
        articleMapper.addArticle(article);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public int addCommentKid(ArticleComment articleComment) {
        articleMapper.updatecomment(articleComment);
        return articleMapper.addCommentKid(articleComment);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public int addComment(ArticleComment articleComment) {
        articleMapper.updatecomment(articleComment);
        return articleMapper.addComment(articleComment);
    }
    @Transactional(readOnly = true)
    @Override
    public List<Article> getInitCheckArticle(Integer adminId, Integer page) {
        PageHelper.startPage(page,5);
        List<Article> articles = articleMapper.selectInitCheckArticle(adminId);
        PageInfo<Article> pageInfo = new PageInfo<>(articles);
        pageInfo.setPageNum(page);
        return pageInfo.getList();
    }

    @Transactional(readOnly = true)
    @Override
    public List<Article> getCheckArticle(Integer page) {
        PageHelper.startPage(page,5);
        List<Article> articles = articleMapper.selectCheckArticle();
        PageInfo<Article> pageInfo = new PageInfo<>(articles);
        pageInfo.setPageNum(page);
        return pageInfo.getList();
    }
    @Transactional(readOnly = true)
    @Override
    public Article getArticleByAid(Integer aid) {
        return articleMapper.selectArticleByAid(aid);
    }
    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public void addArticleCheckMessage(ArticleCheckMessage message) {
        articleMapper.addArticleCheckMessage(message);
        articleMapper.updateArticleStatus(message);
    }
    @Transactional(readOnly = true)
    @Override
    public List<ArticleCheckMessage> getCheckMessage(Integer aid) {
        return articleMapper.selectMessageByAid(aid);
    }
    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public void updateArticlePermit(Integer aid, String astatus) {
        articleMapper.updateArticlePermit(aid,astatus);
    }


    @Transactional(readOnly = true)
    @Override
    public List<Article> selectArticleByUid(Integer uid, Integer count,Integer astatus) {
        return articleMapper.selectArticleByUid(uid,count,astatus);
    }
    @Transactional(readOnly = true)
    @Override
    public Integer selectArticleCount(Integer uid) {
        return articleMapper.selectArticleCount(uid);
    }
    @Transactional(readOnly = true)
    @Override
    public Integer selectCollArtNum(Integer uid) {
        return articleMapper.selectCollArtNum(uid);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public int coll(ArticleCollInfo articleCollInfo) {
        return articleMapper.coll(articleCollInfo);
    }
    @Transactional(readOnly = true)
    @Override
    public ArticleCollInfo getCollInfo(Integer uid, Integer aid) {
        return articleMapper.getCollInfo(uid,aid);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public void unColl(ArticleCollInfo articleCollInfo) {
        articleMapper.unColl(articleCollInfo);
    }
    @Transactional(readOnly = true)
    @Override
    public ArticleCheckMessage getArticleMessage(Integer aid) {
        return articleMapper.getArticleMessage(aid);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public void updateArticle(Article article) {
        articleMapper.updateArticle(article);
    }
}
